////////// the land of the flying raptor and the home of the eye ball ship animation

class Space_ship extends Particle {

  Gravity gravity;

  Collision_detector collision_detector_left;
  Collision_detector collision_detector_right;

  Animation animation_left_eye;
  Animation animation_right_eye;

  Cursor my_cursor;

  Right_eye right_eye;
  Left_eye left_eye;


  Space_ship() {  
    super();

    velocity = 1;
    set_mass(10);

    stage_offset = 12;

    x_loc = 574;
    y_loc = 78;

    my_cursor    = new Cursor();

    left_eye     = new Left_eye(this,75,60,10,10);
    right_eye    = new Right_eye(this,260,120,10,10);//38

    animation_left_eye  = new Animation("leftEye",19,91,54);
    animation_right_eye = new Animation("rightEye",19,274,115);

    gravity = new Slopy_hack();
    collision_detector_left = new Collision_detector();
    collision_detector_right = new Collision_detector();

    collision_detector_left.set_particle_one(this);
    collision_detector_left.set_particle_two(left_eye);

    collision_detector_right.set_particle_one(this);
    collision_detector_right.set_particle_two(right_eye);


    gravity.set_particle_one(this);
    gravity.set_particle_two(my_cursor);

    ship_RENDER_setup();
  }

  boolean collision;

  void math() {


    if((! collision_detector_right.collision) && (!collision_detector_left.collision)) {

      my_cursor.math();

      right_eye.math();
      left_eye.math();

      right_eye.set_collision(collision_detector_right.is_collision());
      left_eye.set_collision(collision_detector_left.is_collision());


      gravity.set_distance(0);
      gravity.apply_gravity();



      super.math();
    }
  }


  void render() {
    if((! collision_detector_right.collision) && (!collision_detector_left.collision)) {

      fill(255,0,0);
      ellipse(x_loc,y_loc,mass,mass);
      ship_RENDER();
    }
    else {
    }

    left_eye.render();
    right_eye.render();
  }



  class Right_eye extends Eye {

    Right_eye(Particle ship,float x_loc, float y_loc, int mass, float dis) {
      super(ship,x_loc,y_loc,mass,dis);
    } 

    void render() {
      if (collision) {
        animation_right_eye.play();
      }
      else {
        fill(100,100,150);
        ellipse(x_loc, y_loc, mass, mass);
      }
    }
  }

  class Left_eye extends Eye {

    Left_eye(Particle ship,float x_loc, float y_loc, int mass, float dis) {
      super(ship,x_loc,y_loc,mass,dis);
    }

    void render() {
      if (collision) {
        animation_left_eye.play();
      }
      else {
        fill(100,100,150);
        ellipse(x_loc, y_loc, mass, mass);
      }
    }
  }



  class Cursor extends Particle {

    Cursor() {
      super();
      set_mass(5);
      velocity = 0;
      x_loc = width;
      y_loc = height;
    }

    void math() {
      x_loc = mouseX;
      y_loc = mouseY;
    }
  }

  class Slopy_hack extends Gravity {

    Slopy_hack() {
    }

    float calculate_strength() {
      strength = 10;

      return strength;
    }
  }

  PImage ship;
  PImage ship1;


  void ship_RENDER_setup() {
    ship =loadImage("data/ship.png");
    ship1=loadImage("data/ship1.png");
  }


  boolean pass;

  void ship_RENDER() {
    // noFill();
    // ellipseMode(RADIUS);
    //ellipse(x_locOne,y_locOne,r1,r1);
    // fill(255);


    imageMode(CENTER);
    if(pass) {
      image(ship,x_loc,y_loc);
      pass = false;
    }
    else {
      image(ship1,x_loc,y_loc);
      pass = true;
    }
  }
}
class Eye extends Particle {

  boolean collision;

  float dis;
  float center_x;
  float center_y;
  Particle ship;

  Eye(Particle ship,float x_loc, float y_loc, int mass, float dis) {
    center_x=x_loc;
    center_y=y_loc;
    set_mass(mass);
    this.dis = dis;
    this.ship = ship;
  }

  void set_collision(boolean collision) {
    this.collision = collision;
  }



  void math() {
    rotation = direction_to(ship.x_loc,ship.y_loc,center_x,center_y)-180;
    x_loc= center_x  +  cos(radians(rotation))*dis;
    y_loc= center_y  +  sin(radians(rotation))*dis;
  }
}

///// not even flying raptors can defeat HACK A SOAReS` REX!

